/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package demonstration.tab;

import java.awt.Color;
import java.awt.Component;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;

/**
 *
 * @author Nastya
 */
public class DeviationRenderer extends JLabel implements TableCellRenderer {

    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        if (!(value instanceof Double)) {
            setText("");
            if (isSelected) {
                setForeground(table.getSelectionForeground());
            } else {
                setForeground(table.getForeground());
            }
            return this;
        }
        Double doubleValue = (Double) value;
        String formattedValue = String.format("%0$f", doubleValue);
        setText(formattedValue);
        if (isSelected) {
            setBackground(table.getSelectionForeground());
        } else {
            if (doubleValue <= 0.2) {
                setForeground(table.getForeground());
            } else if (doubleValue <= 0.4) {
                System.out.println("CAUGHT!");
                setForeground(Color.MAGENTA);
            } else {
                setForeground(Color.RED);
            }
        }
        return this;
    }
}
